﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using Library;

namespace BusinessLayer
{
   public class Product_Detail
    {
        #region "Variables and Properties"
        //Variate 
        private string product_ID;
        private int detail_ID;
        private int detail_Info;
        private int status;

       
        // Property
        public string Product_ID
        {
            get { return product_ID; }
            set { product_ID = value; }
        }
        public int Detail_ID
        {
            get { return detail_ID; }
            set { detail_ID = value; }
        }
        public int Detail_Info
        {
            get { return detail_Info; }
            set { detail_Info = value; }
        }
        public int Status
        {
            get { return status; }
            set { status = value; }
        }
        #endregion
       
        #region "Initial Methods"
        public Product_Detail() { }
        public Product_Detail(SqlDataReader sdr)
        {
            if (sdr != null & !sdr.IsClosed)
            {
                Product_ID = sdr.GetString(0);
                if (sdr.IsDBNull(1))
                    Detail_ID = sdr.GetInt32(1);
                if (sdr.IsDBNull(2))
                    Detail_Info = sdr.GetInt32(2);
                if (sdr.IsDBNull(3))
                    Status = sdr.GetInt32(3);

            }
        }
        #endregion
        #region "Business Methods"
        //Get all Product_Detail
        public static List<Product_Detail> GetAll()
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Product_Detail_SHOWALL";
            List<Product_Detail> lstProduct_Detail = new List<Product_Detail>();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            while (sdr.Read())
            {
                lstProduct_Detail.Add(new Product_Detail(sdr));
            }
            return lstProduct_Detail;
        }

        //Get one Product_Detail
        public static Product_Detail GetOne(int id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Product_ID", id);
            string cmd = "tbl_Product_Detail_SHOWONE";
            Product_Detail product_Detail = new Product_Detail();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            if (sdr.Read())
            {
                product_Detail.Product_ID = sdr.GetString(0);
                if (!sdr.IsDBNull(1))
                    product_Detail.Detail_ID = sdr.GetInt32(1);
                if (!sdr.IsDBNull(2))
                   product_Detail.Detail_Info = sdr.GetInt32(2);
                if (!sdr.IsDBNull(3))
                    product_Detail.Status = sdr.GetInt32(3);

            }
            return product_Detail;
        }

        //Insert a Product_Detail
        public static void Insert(Product_Detail product_Detail)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Detail_Info", product_Detail.Detail_Info);
            string cmd = "tbl_Product_Detail_INSERT";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

        //Update a Product_Detail
        public static void Update(Product_Detail product_Detail)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Product_ID", product_Detail.Product_ID);
            dbh.AddParameter("@Detail_ID", product_Detail.Detail_ID);
            dbh.AddParameter("@Detail_Info", product_Detail.Detail_Info);
            string cmd = "tbl_Product_Detail_UPDATE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
        //Delete a Product_Detail
        public static void Delete(int Id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Product_ID", Id);
            string cmd = "tbl_Product_Detail_DELETE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
        #endregion



    }
}
